package com.fastCms.manager.bim.controller;


import com.fastCms.business.bim.enums.DeviceClassEnum;
import com.fastCms.business.bim.manage.DeviceManageService;
import com.fastCms.business.bim.pojo.entity.DeviceType;
import com.fastCms.business.bim.pojo.po.DeviceAddPO;
import com.fastCms.business.bim.pojo.po.DeviceListPO;
import com.fastCms.business.bim.pojo.po.DeviceUpdatePO;
import com.fastCms.business.bim.pojo.vo.DeviceFiledsVO;
import com.fastCms.business.bim.pojo.vo.DeviceInfoVO;
import com.fastCms.business.bim.pojo.vo.DeviceTypeVO;
import com.fastCms.business.frame.pojo.PageParam;
import com.fastCms.business.frame.pojo.vo.EnumDataVO;
import com.fastCms.business.frame.response.ApiResponse;
import com.fastCms.business.frame.response.ResponseUtil;
import com.fastCms.manager.frame.annotation.UserAccess;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 设备分类表 前端控制器
 * </p>
 *
 * @author liusq
 * @since 2021-03-22
 */
@RestController
@RequestMapping("/device")
@Api(value = "DeviceController", tags = "后端-设备相关接口")
@UserAccess
public class DeviceController {

    @Autowired
    private DeviceManageService deviceManageServiceImpl;

    @ApiOperation(value = "所有设备列表", notes = "")
    @PostMapping("/deviceList")
    public ApiResponse<PageInfo<DeviceInfoVO>> deviceList(@RequestBody PageParam<DeviceListPO> pageParam) {
        PageInfo<DeviceInfoVO> result = deviceManageServiceImpl.deviceList(pageParam);
        return ResponseUtil.success(result);
    }

    @ApiOperation(value = "获取设备大类列表", notes = "")
    @GetMapping("/deviceClass")
    public ApiResponse<List<EnumDataVO>> getDeviceClass() {
        List<EnumDataVO> enumVOs = DeviceClassEnum.getEnumVOs();
        return ResponseUtil.success(enumVOs);
    }

    @ApiOperation(value = "获取设备小类列表", notes = "")
    @GetMapping("/deviceTypes")
    public ApiResponse<List<DeviceTypeVO>> getDeviceTypes() {
        List<DeviceType> deviceTypes = deviceManageServiceImpl.getDeviceTypes();
        return ResponseUtil.success(deviceTypes);
    }

    @ApiOperation(value = "新增设备", notes = "")
    @PostMapping("/addDevice")
    public ApiResponse<Boolean> addDevice(@RequestBody @Valid DeviceAddPO deviceAddPO) {
        ApiResponse<Boolean> result = deviceManageServiceImpl.addDevice(deviceAddPO);
        return result;
    }

    @ApiOperation(value = "修改设备", notes = "")
    @PostMapping("/updateDevice")
    public ApiResponse<Boolean> updateDevice(@RequestBody DeviceUpdatePO deviceUpdatePO) {
        ApiResponse<Boolean> result = deviceManageServiceImpl.updateDevice(deviceUpdatePO);
        return result;
    }

    @ApiOperation(value = "设备信息", notes = "根据设备ID")
    @GetMapping("/deviceInfo/{deviceId}")
    public ApiResponse<DeviceInfoVO> deviceInfo(@PathVariable Integer deviceId) {
        DeviceInfoVO deviceInfoVO = deviceManageServiceImpl.deviceInfo(deviceId);
        return ResponseUtil.success(deviceInfoVO);
    }

    @ApiOperation(value = "删除设备", notes = "根据设备ID")
    @GetMapping("/deleteDevice/{deviceId}")
    public ApiResponse<Boolean> deleteDevice(@PathVariable Integer deviceId) {
        Boolean result = deviceManageServiceImpl.deleteDevice(deviceId);
        return ResponseUtil.success(result);
    }

    @ApiOperation(value = "获取设备动态字段", notes = "")
    @GetMapping("/getDeviceFields/{deviceTypeId}")
    public ApiResponse<List<DeviceFiledsVO>> getDeviceFields(@PathVariable Integer deviceTypeId) {
        List<DeviceFiledsVO> deviceTypes = deviceManageServiceImpl.getDeviceFields(deviceTypeId);
        return ResponseUtil.success(deviceTypes);
    }


}

